import * as types from './mutation-types';
import {router} from '../router/index';
import Cookies from 'js-cookie';
import api from  '@/api/fetch-api';
export const getUser = function ({commit}) {
    try{
        let parameter = {
                areaName:'厦门市',
                zoneCode:'350200'
        };
        api(this,'/api/getDemo',parameter,res => {
            if(res.code==0){
                commit(types.SET_USERINFO, res.data);
            }
        });
    }catch(err){
        console.log('您尚未登陆或者session失效');
        router.push({
            name: 'login'
        });
    }
};
export const getMenuList = function ({commit},userId) {
    try{
        var params = {
            userId:userId,
            owner:"SD_HB_PC"
        };
        debugger;
      /*  getMenuLists(params).then(res =>{
            if (res.code == 0) {
                commit(types.MUNU_LIST, res.data);
                if(res.data!==[]&&res.data!==""){
                    let name = "";
                    for(let i=0;i<res.data.length;i++){
                        for(let j=0;j<res.data[i].children.length;j++){
                            if(name!==""){
                                name =name+ ","+res.data[i].children[j].name;
                            }else{
                                name = res.data[i].children[j].name;
                            }
                        }
                    }
                    Cookies.set("menuList",name);
                }

            }else{
                console.log('获取菜单失败');
            }
        });*/
    }catch(err){
        console.log('获取菜单失败');
        router.push({
            name: 'login'
        });
    }
};
